$(document).ready(function(e){
	var userId;
	mui.plusReady(function() {
		id = plus.navigator.getCookie( "id");
		// userId为null,类型为object
		if(typeof(id) == "string"){
			userId = id;
		}else{
			var iflogin = confirm("暂未登录，是否前去登录？");
			if(iflogin){
				plus.webview.open('../html/before-login.html', 'new', {}, 'slide-in-right', 200);
			}else{
				mui.back();
			}
			return false;
		}
	});
	// 发布帖子
	$("#publish_topic").on("click", function(){
		var title = $("#topicTitle").val();
		if(title == ""){
			mui.toast("标题不能为空哦！");
			$("#topicTitle").css('border', '1px solid #f00');
			return false;
		}else{
			$("#topicTitle").css('border', 'none');
		}
		var content = $("#topicDescribe").val();
		if(userId == undefined){
			var iflogin = confirm("暂未登录，是否前去登录？");
			if(iflogin){
				plus.webview.open('../html/before-login.html', 'new', {}, 'slide-in-right', 200);
			}else{
				mui.back();
			}
			return false;
		}
		$.ajax({
			url:backend_url + "/po/ap.action",
			data:{
				"userId":userId,
				"title":title,
				"content":content
			},
			type:"POST",
			dataType:"json",
			success:function(data){
				if(data.a == true){
					alert("发布成功！");
					mui.back();
				}
			},
			error:function(er){
				console.log(er);
				alert("呃。。网络似乎除了什么问题，请检查网络连接或重试！");
				// window.location.reload();
			}
		});
	});
});